package com.estar.assistsurvy.adapter;

import java.util.List;

import com.estar.assistsurvey.entity.ImageVO;
import com.estar.assistsurvy.R;
import com.estar.assistsurvy.utils.GlideUtiles;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PhotoPreviewAdapter extends BaseAdapter {

	private List<ImageVO> list;
	private Context context;
	private LayoutInflater inflater;
	
	public PhotoPreviewAdapter(List<ImageVO> list, Context context) {
//		super();
		this.list = list;
		this.context = context;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.gridview_imagepreview, null);
			holder=new ViewHolder();
			holder.img=(ImageView) convertView.findViewById(R.id.img);
			holder.index=(TextView) convertView.findViewById(R.id.index);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		ImageVO photo=list.get(position);
//		File file=new File(photo.getPicPath());
//		Glide.with(context)
////		.load("file://"+photo.getPicPath())
//		.load(new File(photo.getPicPath()))
//		.fitCenter()
//		.placeholder(R.drawable.rrklogo)
//		.into(holder.img);
		GlideUtiles.loadIntoUseFitWidth(context, photo.getPicPath(), holder.img);
		holder.index.setText(position+1+"/"+list.size());
		
		return convertView;
	}
	
	private class ViewHolder{
		private ImageView img;
		private TextView index;
	}

}
